package com.ly.demo.weixin.feign;

import com.ly.demo.weixin.interceptor.AccessTokenInterceptor;
import com.ly.demo.weixin.req.GetUserPhoneNumberReq;
import com.ly.demo.weixin.req.QrcodeCreateReq;
import com.ly.demo.weixin.req.SendMsgByTemplateReq;
import com.ly.demo.weixin.req.UserInfoReq;
import com.ly.demo.weixin.rsp.GetUserPhoneNumberRsp;
import com.ly.demo.weixin.rsp.QrCodeCreateRsp;
import com.ly.demo.weixin.rsp.SendMsgByTemplateRsp;
import com.ly.demo.weixin.rsp.WeixinUserInfoRsp;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.cloud.openfeign.SpringQueryMap;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;

/**
 * @description: 微信小程序接口，需要带access_token的接口
 * @author: nieguochen
 * @date: 2024/1/15 13:50
 */
@FeignClient(name = "weixinNeedTokenFeign", url = "https://api.weixin.qq.com", configuration = AccessTokenInterceptor.class)
public interface WeixinNeedTokenFeign {
    /**
     * 获取手机号
     *
     * @param request
     * @return
     */
    @PostMapping(value = "/wxa/business/getuserphonenumber", consumes = MediaType.APPLICATION_JSON_VALUE)
    GetUserPhoneNumberRsp getUserPhoneNumber(GetUserPhoneNumberReq request);


    /**
     * 创建场景二维码
     *
     * @param request
     * @return https://developers.weixin.qq.com/doc/offiaccount/Account_Management/Generating_a_Parametric_QR_Code.html
     */
    @PostMapping(value = "/cgi-bin/qrcode/create", consumes = MediaType.APPLICATION_JSON_VALUE)
    QrCodeCreateRsp qrcodeCreate(QrcodeCreateReq request);

    /**
     * 获取用户信息
     *
     * @param request
     * @return
     * @see  WeixinUserInfoRsp req
     */
    @GetMapping(value = "/cgi-bin/user/info", consumes = MediaType.APPLICATION_JSON_VALUE)
    WeixinUserInfoRsp userInfo(@SpringQueryMap UserInfoReq request);

    /**
     * 发送模版消息
     * https://developers.weixin.qq.com/doc/offiaccount/Message_Management/Template_Message_Interface.html#5
     */
    @PostMapping(value = "/cgi-bin/message/template/send", consumes = MediaType.APPLICATION_JSON_VALUE)
    SendMsgByTemplateRsp sendMsgByTemplate(SendMsgByTemplateReq request);
}
